package com.ea.common.advice;



import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;


import org.springframework.http.HttpStatus;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.ResponseStatus;










/**
 * springmvc异常处理
 * 
 * @author jun
 *
 */

@ControllerAdvice
public class ExceptionHandlerAdvice {

//	private static final Logger log = LoggerFactory.getLogger("adminLogger");

	/**
	 * 账号密码错误
	 * @param exception
	 * @param model
	 * @return
	 */
	@ExceptionHandler({UnknownAccountException.class,IncorrectCredentialsException.class})
	@ResponseStatus(HttpStatus.UNAUTHORIZED)
	public String loginException(Exception exception, Model model) {
//		String username = getRequest().getParameter("username");
		//	        LogManager.me().executeLog(LogTaskFactory.loginLog(username, "账号密码错误", getIp()));
		model.addAttribute("tips", exception.getMessage());
		return "login";
		//		return new ResponseInfo(HttpStatus.BAD_REQUEST.value() + "", exception.getMessage());
	}



	@ExceptionHandler({IllegalArgumentException.class })
	@ResponseStatus(HttpStatus.BAD_REQUEST)
	public ResponseInfo badRequestException(IllegalArgumentException exception) {
		return new ResponseInfo(HttpStatus.BAD_REQUEST.value() + "", exception.getMessage());
	}
//
//
//
//
//	@ExceptionHandler({ UnauthorizedException.class })
//	@ResponseStatus(HttpStatus.FORBIDDEN)
//	public ResponseInfo forbidden(Exception exception) {
//		return new ResponseInfo(HttpStatus.FORBIDDEN.value() + "", exception.getMessage());
//	}
//
//	@ExceptionHandler({ MissingServletRequestParameterException.class, HttpMessageNotReadableException.class,
//		UnsatisfiedServletRequestParameterException.class, MethodArgumentTypeMismatchException.class })
//	@ResponseStatus(HttpStatus.BAD_REQUEST)
//	public ResponseInfo badRequestException(Exception exception) {
//		return new ResponseInfo(HttpStatus.BAD_REQUEST.value() + "", exception.getMessage());
//	}
//
//	@ExceptionHandler(Throwable.class)
//	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//	public ResponseInfo exception(Throwable throwable) {
//		log.error("系统异常", throwable);
//		return new ResponseInfo(HttpStatus.INTERNAL_SERVER_ERROR.value() + "", throwable.getMessage());
//
//	}



	
}
